﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using LCTNote.Models.ViewModels;
using LCTNote.Models.DataModels;

namespace LCTNote.Services
{
    class BanGhiService : Service
    {
        /// <summary>
        /// Lấy bản ghi theo mã thư mục
        /// </summary>
        /// <param name="maThuMuc">Mã thư mục</param>
        /// <returns></returns>
        public static List<BanGhiViewModel> layBanGhiTheoMaThuMuc(int maThuMuc)
        {
            return executeDataReader_List<BanGhiViewModel>
                (
                    "Note_layBanGhiTheoMaThumuc",
                    new object[]
                    {
                        maThuMuc
                    }
                );
        }

        public static BanGhiViewModel layBanGhiTheoMaBanGhi(int maBanGhi)
        {
            return executeDataReader<BanGhiViewModel>
                (
                    "Note_layBanGhiTheoMaBanGhi",
                    new object[]
                    {
                        maBanGhi
                    }
                );
        }
        
        /// <summary>
        /// Thêm bản ghi
        /// </summary>
        /// <param name="banGhi">Gồm nội dung, tiêu đề</param>
        /// <returns></returns>
        public static bool themBanGhi(BanGhiDataModel banGhi)
        {
            return executeNonQuery
                (
                    "Note_themBanGhi",
                    new object[]
                    {
                        banGhi.noiDung,
                        banGhi.noiDungDinhDang,
                        (banGhi.chuoiMaTuKhoa == "") ? DBNull.Value : (object)banGhi.chuoiMaTuKhoa,
                        banGhi.thoiGianCapNhat,
                        (banGhi.chuoiMaTapTin == "") ? DBNull.Value : (object)banGhi.chuoiMaTapTin,
                        banGhi.maThuMuc,
                        banGhi.tieuDe,
                        banGhi.thoiGianBao,
                        banGhi.Ghim,
                        banGhi.maNguoiTao
                    }
                );
        }

        public static bool xoaBanGhi(int maBanGhi)
        {
            return executeNonQuery
                (
                    "Note_xoaBanGhi",
                    new object[]
                    {
                        maBanGhi
                    }
                );
        }

        public static bool capNhatBanGhi(BanGhiDataModel banGhi)
        {
            return executeNonQuery
                (
                    "Note_capNhatBanGhiTheoMaBanGhi",
                    new object[]
                    {
                        banGhi.ma,
                        banGhi.noiDung,
                        banGhi.noiDungDinhDang,
                        (banGhi.chuoiMaTuKhoa == "") ? DBNull.Value : (object)banGhi.chuoiMaTuKhoa,
                        banGhi.thoiGianCapNhat,
                        (banGhi.chuoiMaTapTin == "") ? DBNull.Value : (object)banGhi.chuoiMaTapTin,
                        banGhi.maThuMuc,
                        banGhi.tieuDe,
                        banGhi.thoiGianBao,
                        banGhi.Ghim                        
                    }
                );
        }
    }
}
